package com.linq.cool.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linq.cool.api.domain.SysLoginLog;
import com.linq.cool.common.constants.Constants;
import com.linq.cool.system.dto.SysLoginLogQueryDTO;
import com.linq.cool.system.mapper.SysLoginLogMapper;
import com.linq.cool.system.service.SysLoginLogService;
import org.springframework.stereotype.Service;

/**
 * @Author: yqlin
 * @Date: 2020/12/29 19:41
 * @Description:
 * @Version: 1.0.0
 */
@Service
public class SysLoginLogServiceImpl extends ServiceImpl<SysLoginLogMapper, SysLoginLog> implements SysLoginLogService {
    @Override
    public IPage<SysLoginLog> listByPage(IPage<SysLoginLog> page, SysLoginLogQueryDTO dto) {
        return this.page(page, this.getLambdaQueryWrapper(dto));
    }

    @Override
    public void clean() {
        baseMapper.clean();
    }

    private LambdaQueryWrapper<SysLoginLog> getLambdaQueryWrapper(SysLoginLogQueryDTO dto) {
        return new LambdaQueryWrapper<SysLoginLog>()
                .like(StringUtils.checkValNotNull(dto.getIp()), SysLoginLog::getIp, dto.getIp())
                .eq(StringUtils.checkValNotNull(dto.getStatus()), SysLoginLog::getStatus, dto.getStatus())
                .like(StringUtils.checkValNotNull(dto.getUsername()), SysLoginLog::getUsername, dto.getUsername())
                .like(StringUtils.checkValNotNull(dto.getCity()), SysLoginLog::getCity, dto.getCity())
                .between(StringUtils.checkValNotNull(dto.getParams().get(Constants.BEGIN_TIME)), SysLoginLog::getGmtCreate, dto.getParams().get(Constants.BEGIN_TIME), dto.getParams().get(Constants.END_TIME))
                ;
    }
}


